// pages/mv/mv.js
Page({

  /* 页面的初始数据 */
  data: {
    mvdata:[]
  },

  /* 生命周期函数--监听页面加载 */
  onLoad: function (options) {
     this.getmvData()
  },
  // 找到mv数据
  getmvData:function(){
     wx.request({
       url: 'http://localhost:3000/mv/exclusive/rcmd',
       success: (result) => {
        //  遍历数据
        result.data.data.forEach(item => {
            // 播放量格式化，返回字符串
            const countStr= this.setcount(item.playCount)
            //  给每条数据增加这个字符串
            item.countStr=countStr
        })
        this.setData({
          mvdata:result
        })
       }, 
     })
  },
  // 处理播放量格式化的方法
  setcount:function(playcount){
    let playcountstr = ""
    if (playcount >= 10000) {
      let c1 = Math.floor(playcount / 10000)
      let c2 = playcount % 10000
      playcountstr = c1 + "." + c2
      playcountstr = playcountstr.slice(0, -3) + "万"
      return playcountstr
    } else {
      return playcount
  }
},

  // 点击播放mv
  play:function(e){
    const mid =e.currentTarget.dataset.mid
    wx.navigateTo({
      url: '/pages/mvplay/mvplay?mvid='+mid,
    }) 
  },
})